<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div class="container1">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>

    <div class="container2">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>

    <div class="container3">
        <button>按钮一</button>
        <button>按钮二</button>
        <button>按钮三</button>
        <div>111</div>
        <div>222</div>
        <div>333</div>
    </div>
    <button class="btn">点击我切换</button>
    <script>


        function Tab(btns, divs) {
            this.btns = btns;
            this.divs = divs;
            this.btnsForFn();
        }
        Tab.prototype.btnsForFn = function () {
            this.btns.forEach((btn, key) => {
                btn.onclick = () => {
                    this.divForFn(key);
                }
            })
        }

        Tab.prototype.divForFn = function (key) {
            this.divs.forEach((div, k) => {
                if (k == key) {
                    this.divs[k].style.display = "block";
                } else {
                    this.divs[k].style.display = "none";
                }
            })
        }




        var btns = document.querySelectorAll(".container1 button");
        var divs = document.querySelectorAll(".container1 div");
        var tab1 =   new Tab(btns, divs);

        var btns2 = document.querySelectorAll(".container2 button");
        var divs2 = document.querySelectorAll(".container2 div");
        var tab2 =   new Tab(btns2, divs2);
        let num = 0;
        setInterval(()=>{
            tab2.divForFn(num);
            num++
            if(num>2){
                num = 0;
            }
        },1000)



        var btns3 = document.querySelectorAll(".container3 button");
        var divs3 = document.querySelectorAll(".container3 div");
        var tab3=   new Tab(btns3, divs3);
        let num2 = 0;
        document.querySelector(".btn").onclick = function(){
            tab3.divForFn(num2);
            num2++
            if(num2>2){
                num2 = 0;
            }
        }

        // 1.复习 2. 选项卡 和 拖拽改成 ES6；

    </script>
</body>

</html>